home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 18 / CU Amiga Magazine's Super CD-ROM 18 (1997)(EMAP Images)(GB)[!][issue 1998-01].iso / CUCD / Online / CNetDemo / cnet / sdk / Examples / MenuBits.c < prev    next >
Encoding:
Text File  |  1997-09-04  |  25.4 KB  |  720 lines

  1. /************************************************************************
  2.  *    CNet/3 and CNet/4  C language interface routines and examples     *
  3.  *                                                                      *
  4.  *  copyright © 1996 ZenMetal Software ... this code may be freely      *
  5.  *  distributed to and used by registered CNet owners EXCLUSIVELY.      *
  6.  *  Other distribution is in violation of copyright laws.               *
  7.  ************************************************************************/
  8.  
  9.  
  10.  
  11. /************************************************************************
  12.  *                          Function prototypes                         *
  13.  ************************************************************************/
  14. void        CallHost( UBYTE c );
  15. void        ShutDown( char *spawn );
  16. void        GetOut( void );
  17. void        LoadError( void );
  18.  
  19.  
  20. /************************************************************************
  21.  *                           Global Variables                           *
  22.  ************************************************************************/
  23. struct MsgPort         *replyp;    /* Some communication details ...    */
  24. struct CPort           *cport;
  25. struct CMessage        cmess;
  26. struct MainPort        *myp;        /* Pointer to CNet port--ALL info!    */
  27. struct PortData        *z;
  28. char                     **bm;
  29. struct Library         *CNetBase = NULL;
  30. struct SignalSemaphore *SEM;
  31.  
  32.  
  33.  
  34. /************************************************************************
  35.  *                             Main routine                             *
  36.  ************************************************************************/
  37. void main( int argc, char **argv )
  38. {
  39.     int zzz=0;
  40.     char text[30];
  41.  
  42.     Forbid();
  43.     if(argc > 1)
  44.         cport = (struct CPort *)FindPort( argv[1] );
  45.     Permit();
  46.  
  47.     if( argc<2 || !(cport) ) {
  48.         printf("This is a CNet C program.\n");
  49.         exit(0);
  50.         }
  51.  
  52.     if( !(replyp = CreatePort( 0,0 )))
  53.         exit(0);
  54.  
  55.     cmess.cn_Message.mn_ReplyPort   = replyp;
  56.     cmess.cn_Message.mn_Length      = sizeof( struct CMessage );
  57.     cmess.cn_Message.mn_Node.ln_Name= "cstuff";
  58.  
  59.     // CNet version check
  60.     if( cport->ack != 30 ) {    // change "30" to be compatible with only pre 4.13 systems
  61.         cport->ack = 1;
  62.         LoadError();
  63.         }
  64.  
  65. //    if( cport->ack != 40 )      // Replace the code above with this
  66. //        if( cport->ack != 30 )   // to support both 3.x and 4.x systems
  67. //            {
  68. //            cport->ack = 1;
  69. //            goto err;
  70. //            }
  71.  
  72.     cport->ack = 0;
  73.  
  74.     z    = cport->zp;
  75.     myp  = cport->myp;
  76.     SEM  = myp->SEM;
  77.     bm   = z->bm;
  78.  
  79.     if( !(CNetBase = OpenLibrary( "cnet.library", 4 )) ) // <- NOTE version 4 - can be changed to 3 to make compatible with older CNet releases!
  80.         LoadError();
  81.  
  82. /************************************************************************
  83.  *           End of CNet setup - YOUR CUSTOM CODE STARTS HERE           *
  84.  ************************************************************************/
  85.  
  86.     PutText( "\nu1check bitsu0\n" );
  87.     for(zzz=4;zzz>=0;zzz--)
  88.         {
  89.         switch(zzz)
  90.             {
  91.             case 0:
  92.                 sprintf(text, "DOORS CLOSED");
  93.                 break;
  94.             case 1:
  95.                 sprintf(text, "FILES CLOSED");
  96.                 break;
  97.             case 2:
  98.                 sprintf(text, "MSGS CLOSED ");
  99.                 break;
  100.             case 3:
  101.                 sprintf(text, "DOORS CLOSED");
  102.                 break;
  103.             case 4:
  104.                 sprintf(text, "NO NEW USERS");
  105.                 break;
  106.             }
  107.         sprintf(z->ABuffer, "%s: %s\n", text, myp->pc[z->InPort].check & (1<<zzz) ? "TRUE":"FALSE");
  108.         PutA();
  109.         }
  110.  
  111.  
  112.  
  113.  
  114.     /* exit back to CNet - always call GetOut() to exit back to CNet! */
  115.     GetOut();
  116. }
  117.  
  118.  
  119. /**************************************************************************
  120.  *       Routine called if Load error (wrong CNet version, etc,...        *
  121.  **************************************************************************/
  122. void LoadError( void )
  123. {
  124.     DeletePort( replyp );
  125.     exit(0);
  126. }
  127.  
  128. /************************************************************************
  129.  *                           Generic EXIT code                          *
  130.  ************************************************************************/
  131. void GetOut( void )
  132. {
  133.     ShutDown( NULL );
  134.     DeletePort( replyp );
  135.     exit(0);
  136. }
  137.  
  138.  
  139. /**************************************************************************
  140.  *                         another file to run?                           *
  141.  **************************************************************************/
  142. void ShutDown( char *spawn )
  143. {
  144.     /* spawn = full path/file to run */
  145.     if( spawn )
  146.         strcpy( z->CSpawn, spawn );
  147.  
  148.     CallHost( 0 );
  149. }
  150.  
  151.  
  152. void CallHost( UBYTE c )
  153. {
  154.     cmess.command = c;
  155.     PutMsg  ( (struct MsgPort *)cport, (struct Message *)&cmess );
  156.     WaitPort( replyp );
  157.     GetMsg  ( replyp );
  158. }
  159.  
  160. void PutText( char *text )
  161. {
  162.     cmess.arg1 = (ULONG)text;    /* text to print        */
  163.     CallHost( 1 );
  164. }
  165.  
  166. void PutA( void )
  167. {
  168.     PutText( z->ABuffer );
  169. }
  170.  
  171.  
  172. /**************************************************************************
  173.  *    ENTERLINE FLAGS:                                                    *
  174.  *      1: All capitalized                                                *
  175.  *      2: FILENAME.  Don't allow =":; or asterisk                        *
  176.  *      4: Begin with existing z.InBuffer                                 *
  177.  *      8: Chop leading spaces                                            *
  178.  *     16: Force 1st letter of word caps                                  *
  179.  *     32: Force all others lower case                                    *
  180.  *     64: Numeric input only                                             *
  181.  *    128: Print input box (.)                                            *
  182.  *    256: DO allow MCI                                                   *
  183.  *    512: HANDLES/SPECIAL.  Don't allow ^_`{|}~@                         *
  184.  *   1024: Exit for . or / at beginning of line                           *
  185.  *   2048: Exit for backspace at beginning of line                        *
  186.  *   4096: Do not allow OLM's to appear while editing                     *
  187.  *   8192: Allow Chat break in at this prompt. COMMAND PROMPT.            *
  188.  *  16384: Don't allow SPACE, either                                      *
  189.  *  32768: DON'T ALLOW MOVEMENT                                           *
  190.  *  65536: Don't allow forward slash                                      *
  191.  **************************************************************************/
  192. int EnterLine( UBYTE len, ULONG flags, char *prompt )
  193. {
  194.     cmess.arg1 = (ULONG)len;    /* how many chars max to input    */
  195.     cmess.arg2 = (ULONG)flags;    /* 1=UpperCase            */
  196.     cmess.arg3 = (ULONG)prompt;    /* text to print before input    */
  197.     CallHost( 2 );            /* result is in z->InBuffer    */
  198.     return( (int)strlen( z->InBuffer ));
  199. }
  200.  
  201.  
  202. /**************************************************************************
  203.  *                       Stop until a key is pressed                      *
  204.  **************************************************************************/
  205. char OneKey( void )
  206. {
  207.     CallHost( 3 );
  208.     return( (char)cmess.result );    /* returns key pressed */
  209. }
  210.  
  211.  
  212. /**************************************************************************
  213.  *
  214.  **************************************************************************/
  215. void EnterPassword( UBYTE len )
  216. {
  217.     cmess.arg1 = (ULONG)len;    /* max number of characters */
  218.     CallHost( 4 );
  219. }
  220.  
  221. /**************************************************************************
  222.  *                 Check z->InBuffer for Chat, OLM, etc                   *
  223.  **************************************************************************/
  224. long CommonCommands( void )
  225. {
  226.     CallHost( 5 );
  227.     return( (long)cmess.result );
  228. }
  229.  
  230.  
  231. /**************************************************************************
  232.  *
  233.  **************************************************************************/
  234. UBYTE ReadFile( char *path, UBYTE flags )
  235. {
  236.     cmess.arg1 = (ULONG)path;
  237.     cmess.arg2 = (ULONG)flags;          /* 1 = print File Not Found */
  238.     CallHost( 6 );
  239.     return( (UBYTE)cmess.result );      /* returns FALSE if File Not Found */
  240. }
  241.  
  242. /**************************************************************************
  243.  *        Sets the "Action" or "Where" field for the user's port          *
  244.  *      ** remember to retain and restore the previous z->DOING **        *
  245.  **************************************************************************/
  246. void SetDoing( char *what )
  247. {
  248.     cmess.arg1 = (ULONG)what;
  249.     CallHost( 7 );
  250. }
  251.  
  252.  
  253. /**************************************************************************
  254.  *Invokes the CNet editor according to user's preference of line or Visual*
  255.  **************************************************************************/
  256. void CallEditor( short max, short inlines )
  257. {
  258.     cmess.arg1 = (ULONG)max;    /* Maximum number of lines (250)*/
  259.     cmess.arg2 = (ULONG)inlines;    /* TRUE/FALSE use existing _edbuff? */
  260.     CallHost( 8 );
  261. }
  262.  
  263. /**************************************************************************
  264.  *             Read text file with MCI/graphic interpretation             *
  265.  **************************************************************************/
  266. UBYTE ReadGraphics( char *path, char flags )
  267. {
  268.     cmess.arg1 = (ULONG)path;
  269.     cmess.arg2 = (ULONG)flags;    /* 1 = print File Not Found    */
  270.     CallHost( 9 );
  271.     return( (UBYTE)cmess.result );        /* FALSE if File Not Found    */
  272. }
  273.  
  274. /**************************************************************************
  275.  *  Construct a date in CNet format - like that seen in the port titlebar *
  276.  **************************************************************************/
  277. void MakeDate( struct IsDate *date, char *output )
  278. {
  279.     cmess.arg1 = (ULONG)date;
  280.     cmess.arg2 = (ULONG)output;
  281.     CallHost( 10 );
  282. }
  283.  
  284.  
  285. /**************************************************************************
  286.  *                     Load userdata for account "id"                     *
  287.  **************************************************************************/
  288. UBYTE ReadAccount( short id, struct UserData *user )
  289. {
  290.     cmess.arg1 = (ULONG)id;
  291.     cmess.arg2 = (ULONG)user;
  292.     CallHost( 11 );
  293.     return( (UBYTE)cmess.result );
  294. }
  295.  
  296. /**************************************************************************
  297.  *           Saves an account after editing/changing attributes           *
  298.  **************************************************************************/
  299. UBYTE SaveAccount( struct UserData *user, short id )
  300. {
  301.     cmess.arg1 = (ULONG)user;
  302.     cmess.arg2 = (ULONG)id;
  303.     CallHost( 12 );
  304.     return( (UBYTE)cmess.result );
  305. }
  306.  
  307. /**************************************************************************
  308.  *         add charge amount "a" to charge schedule number "n"            *
  309.  **************************************************************************/
  310. UBYTE AddCharge( short n, short a )
  311. {
  312.     cmess.arg1 = (ULONG)n;
  313.     cmess.arg2 = (ULONG)a;
  314.     CallHost( 13 );
  315.     return( (UBYTE)cmess.result );
  316. }
  317.  
  318. /**************************************************************************
  319.  *
  320.  **************************************************************************/
  321. UBYTE CheckBalance( short n, short a )
  322. {
  323.     cmess.arg1 = (ULONG)n;
  324.     cmess.arg2 = (ULONG)a;
  325.     CallHost( 14 );
  326.     return( (UBYTE)cmess.result );
  327. }
  328.  
  329. /***************************************************************************
  330.  * Get text from user.  Results are placed in z.GBuffer[] array of strings *
  331.  * note that there are 16 lines MAX and each line may hold up to 80        *
  332.  * characters                                                              *
  333.  ***************************************************************************/
  334. int EnterText( char firstchar, short maxchars, short perline, short maxlines )
  335. {
  336.     cmess.arg1 = (ULONG)firstchar;
  337.     cmess.arg2 = (ULONG)maxchars;
  338.     cmess.arg3 = (ULONG)perline;
  339.     cmess.arg4 = (ULONG)maxlines;
  340.     CallHost( 15 );
  341.     return( (int)cmess.result );
  342. }
  343.  
  344. /**************************************************************************
  345.  *
  346.  **************************************************************************/
  347. long ConferenceWait( short a )
  348. {
  349.     cmess.arg1 = (ULONG) a;
  350.     CallHost( 16 );
  351.     return( (long)cmess.result );
  352. }
  353.  
  354.  
  355. /****************************************************************************
  356.  * Update the current time, load the user's bbstext translation, charges    *
  357.  * If the user has little time remaining, print "you have xx minutes left", *
  358.  * force Events to be checked for pending event execution..                 *
  359.  ****************************************************************************/
  360. void CheckChanges( void )
  361. {
  362.     CallHost( 17 );
  363. }
  364.  
  365.  
  366. /**************************************************************************
  367.  *      Converts a CNet access/range string to a packed LONG value        *
  368.  **************************************************************************/
  369. long ConvertAccess( char *s )
  370. {
  371.     cmess.arg1 = (ULONG)s;
  372.     CallHost( 18 );
  373.     return( (long)cmess.result );
  374. }
  375.  
  376.  
  377. /**************************************************************************
  378.  * return the number of bytes free on device specified by s               *
  379.  * if q==0, the result is displayed to the user by GetFree()              *
  380.  **************************************************************************/
  381. long GetFree( char *s, UBYTE q )
  382. {
  383.     cmess.arg1 = (ULONG)s;
  384.     cmess.arg2 = (ULONG)q;
  385.     CallHost( 19 );
  386.     return( (long)cmess.result );
  387. }
  388.  
  389. /**************************************************************************
  390.  *    Find an account based on account number, Handle or real name        *
  391.  *    This is the same routine that, if the user is not found, pops up    *
  392.  *    the mini-userlist for user choice.                                  *
  393.  **************************************************************************/
  394. short FindAccount( char *a, struct UserData *b )
  395. {
  396.     cmess.arg1 = (ULONG)a;
  397.     cmess.arg2 = (ULONG)b;
  398.     CallHost( 20 );
  399.     return( (short)cmess.result );
  400. }
  401.  
  402.  
  403. /**************************************************************************
  404.  *  Forces CNet to flush/check it's buffers and parse/update the keyboard *
  405.  *  buffers                                                               *
  406.  **************************************************************************/
  407. void CheckFlowControl( void )
  408. {
  409.     CallHost( 21 );
  410. }
  411.  
  412. /**************************************************************************
  413.  * list the contents of a directory (the user will be prompted for        *
  414.  * directory name).                                                       *
  415.  *                                                                        *
  416.  * options: a = allow selection of files to user's select list            *
  417.  *                                                                        *
  418.  *          b = 1: select and download immediately                        *
  419.  *              2: allow wildcard pattern                                 *
  420.  *                                                                        *
  421.  *          c = list files newer than the date specified by c             *
  422.  *              c is a properly filled out Cnet IsDate structure          *
  423.  **************************************************************************/
  424. long ListDir( UBYTE a, UBYTE b, struct IsDate *c )
  425. {
  426.     cmess.arg1 = (ULONG)a;
  427.     cmess.arg2 = (ULONG)b;
  428.     cmess.arg3 = (ULONG)c;
  429.     CallHost( 22 );
  430.     return( (long)cmess.result );
  431. }
  432.  
  433.  
  434. /**************************************************************************
  435.  * Read the next base/udbase message                                      *
  436.  **************************************************************************/
  437. UBYTE Rnext( void )
  438. {
  439.     CallHost( 24 );
  440.     return( (UBYTE)cmess.result );
  441. }
  442.  
  443. /***************************************************************************
  444.  * Parse the contents of z->InBuffer into z->pitems.  Parses up to numargs *
  445.  * items                                                                   *
  446.  ***************************************************************************/
  447. void ParseCommandLine( UBYTE numargs )
  448. {
  449.     cmess.arg1 = (ULONG)numargs;
  450.     CallHost( 25 );
  451. }
  452.  
  453.  
  454. /**************************************************************************
  455.  *  Takes the contents of z->InBuffer and searches for a matching command *
  456.  *  in menu "num" of BBSMENU.                                             *
  457.  **************************************************************************/
  458. short FindCommand( short num )
  459. {
  460.     cmess.arg1 = (ULONG) num;
  461.     CallHost( 26 );
  462.     return( (short)cmess.result );
  463. }
  464.  
  465. /**************************************************************************
  466.  * Open the filename specified by a, seek to position b in the file       *
  467.  * and display the contents of the file from point b to EOF               *
  468.  **************************************************************************/
  469. void ReadMessagePoint( char *a, long b )
  470. {
  471.     cmess.arg1 = (ULONG) a;
  472.     cmess.arg2 = (ULONG) b;
  473.     CallHost( 27 );
  474. }
  475.  
  476. /**************************************************************************
  477.  * Use the CNet editor to edit the file specified by "file"               *
  478.  **************************************************************************/
  479. void EditMessage( char *file )
  480. {
  481.     cmess.arg1 = (ULONG) file;
  482.     CallHost( 28 );
  483. }
  484.  
  485. /***************************************************************************
  486.  * Load the text from the file-handle given and insert it into the current *
  487.  * port's editor file                                                      *
  488.  ***************************************************************************/
  489. void LoadText( BPTR fh )
  490. {
  491.     cmess.arg1 = (ULONG) fh;
  492.     CallHost( 29 );
  493. }
  494.  
  495.  
  496. /**************************************************************************
  497.  *    1000000 mics = 1 second                                                *
  498.  **************************************************************************/
  499. char WaitForInput( long mics )
  500. {
  501.     cmess.arg1 = (ULONG) mics;
  502.     CallHost( 31 );
  503.     return( (char)cmess.result );
  504. }
  505.  
  506.  
  507. /**************************************************************************
  508.  *                       Select and download a file.                      *
  509.  *                                                                        *
  510.  * file  = full path/filename                                             *
  511.  *                                                                        *
  512.  * flags = 0 -> select without immediate download                         *
  513.  *       = 1 -> select and download immediately                           *
  514.  *                                                                        *
  515.  * flag values below are new for v4.11                                    *
  516.  *                                                                        *
  517.  *       = 2 -> delete file after downloading/no immediate download       *
  518.  *       = 3 -> delete file after downloading/download immediate.         *
  519.  **************************************************************************/
  520. UBYTE SelectAndDownload( char *file, UBYTE flags )
  521. {
  522.     cmess.arg1 = (ULONG)file;
  523.     cmess.arg2 = (ULONG)flags;
  524.     CallHost( 39 );
  525.     return( (UBYTE)cmess.result );
  526. }
  527.  
  528.  
  529. /**************************************************************************
  530.  * file: the ".vde" filename, without the ".vde"!                         *
  531.  * data: pointer to the structure you are going to edit                   *
  532.  * size: structure length in bytes                                        *
  533.  *                                                                        *
  534.  * returns: TRUE  if structure has been changed                           *
  535.  *          FALSE otherwise                                               *
  536.  **************************************************************************/
  537. short VisualDataEditor( char *file, void *data, long size )
  538. {
  539.     cmess.arg1 = (ULONG)file;
  540.     cmess.arg2 = (ULONG)data;
  541.     cmess.arg3 = (ULONG)size;
  542.     CallHost( 40 );
  543.     return( (short)cmess.result );
  544. }
  545.  
  546. /**************************************************************************
  547.  * In preparation for an ExtUpload, this function                         *
  548.  * sets the minimum number of free bytes to maintain on the    drive.        *
  549.  **************************************************************************/
  550. void ExtSetMinFree( long free )
  551. {
  552.     cmess.arg1 = (ULONG)free;
  553.     CallHost( 42 );
  554. }
  555.  
  556.  
  557. /**************************************************************************
  558.  * In preparation for an ExtDownload or an ExtUpload, this function       *
  559.  * sets the protocol to be used.  If you send NULL, it will allow the     *
  560.  * user to choose his OWN protocol.                                       *
  561.  *                                                                        *
  562.  * Otherwise, you may select 'a' to be the first letter of a valid        *
  563.  * system protocol (from BBSPROTO file), such as 'x', 'z', etc.           *
  564.  *                                                                        *
  565.  * TRUE will be returned if a protocol is selected and ready, FALSE       *
  566.  * if there is a problem.                                                 *
  567.  **************************************************************************/
  568. UBYTE ExtSetProtocol( char a )
  569. {
  570.     cmess.arg1 = (ULONG)a;
  571.     CallHost( 43 );
  572.     return( (UBYTE)cmess.result );
  573. }
  574.  
  575.  
  576.  
  577. /**************************************************************************
  578.  * This routine allows the user to download the SINGLE file specified     *
  579.  * by the FULL PATH 'args'.                                               *
  580.  *                                                                        *
  581.  *    Currently, NULL is always returned.                                    *
  582.  **************************************************************************/
  583. char *ExtDownload( char *args )
  584. {
  585.     cmess.arg1 = (ULONG)args;
  586.     CallHost( 44 );
  587.     return( (char *)cmess.result );
  588. }
  589.  
  590.  
  591. /**************************************************************************
  592.  * This routine allows the user to upload the file specified by           *
  593.  * 'args'.  The path for uploading will be taken from the path            *
  594.  * in 'args'.  If you do NOT specify a path, the file(s) will             *
  595.  * appear in the user's HOME directory.                                   *
  596.  *                                                                        *
  597.  * Note that with batch protocols like ZMODEM, the filename(s) are        *
  598.  * taken from the header packet information, and may NOT be the           *
  599.  * same as what you have requested the user upload.  For this reason,     *
  600.  * you should have uploads occur in a TEMP directory, and search that     *
  601.  * directory yourself for new files.                                      *
  602.  *                                                                        *
  603.  * Currently, NULL is always returned.                                    *
  604.  **************************************************************************/
  605. char *ExtUpload( char *args )
  606. {
  607.     cmess.arg1 = (ULONG)args;
  608.     CallHost( 45 );
  609.     return( (char *)cmess.result );
  610. }
  611.  
  612.  
  613. /**************************************************************************
  614.  * compare two strings and return result                                  *
  615.  *                                                                        *
  616.  * result: 0 if equal                                                     *
  617.  *        >0 if s is alphabetically "higher" than t                       *
  618.  *        <0 if t is alphabetically "higher" than s                       *
  619.  **************************************************************************/
  620. short compstra( char *s, char *t )
  621. {
  622.     for( ; tolower(*s) == tolower(*t); s++, t++)
  623.         if( !*s ) return 0;
  624.  
  625.     return (short)( tolower(*s)-tolower(*t) );
  626. }
  627.  
  628.  
  629. /**************************************************************************
  630.  * Print the prompt string passed as "a" and return the user's            *
  631.  * YES or NO equivalent result.  1=YES, 2=NO                              *
  632.  **************************************************************************/
  633. UBYTE PutQ( char *a )
  634. {
  635.     PutText( a );
  636.     return (UBYTE)(z->MCIcreg[0][0]=='1') ;
  637. }
  638.  
  639. /**************************************************************************
  640.  * Isn't it obvious enough? ;-)
  641.  **************************************************************************/
  642. void DoReturn( void )
  643. {
  644.     PutText("\n");
  645. }
  646.  
  647. /**************************************************************************
  648.  * Create the editor filename used for the current port and place it      *
  649.  * in the string array passed as "path"                                   *
  650.  **************************************************************************/
  651. void MakeEd( char *path )
  652. {
  653.     sprintf( path, "%s_edbuff%d", myp->gc.ZIPpath, z->InPort );
  654. }
  655.  
  656.  
  657. /**************************************************************************
  658.  * Delete the editor file                                                 *
  659.  **************************************************************************/
  660. void DeleteEd( void )
  661. {
  662.     char    filename[80];
  663.  
  664.     MakeEd    ( filename ) ;
  665.     DeleteFile( filename ) ;
  666. }
  667.  
  668. /**************************************************************************
  669.  * Open the file used for the editor and return the filehandle (BPTR)     *
  670.  **************************************************************************/
  671. BPTR OpenEd( long mode )
  672. {
  673.     char    filename[80];
  674.  
  675.     MakeEd( filename );
  676.  
  677.     return Open( filename, mode );
  678. }
  679.  
  680. /**************************************************************************
  681.  * insert the contents of the file belonging to filehandle "fp" into      *
  682.  * the current port's editor file                                         *
  683.  **************************************************************************/
  684. void PrepEditor( BPTR fp )
  685. {
  686.     BPTR    kp;
  687.     char    buff[100];
  688.  
  689.     if( fp ) {
  690.         if( kp = OpenEd( MODE_NEWFILE ) ) {
  691.             while( FGets( fp, buff, 82 ) && buff[0]!=26 )
  692.                    FPuts( kp, buff     ) ;
  693.  
  694.             Close( kp );
  695.         }
  696.     }
  697.     else    DeleteEd();
  698. }
  699.  
  700. /**************************************************************************
  701.  * Save the contents of the current port's editor file into the file      *
  702.  * belonging to filehandle "fp"                                           *
  703.  **************************************************************************/
  704. void SaveEditor( BPTR fp, UBYTE eof )
  705. {
  706.     BPTR    kp;
  707.     char    buff[100];
  708.  
  709.     if( kp = OpenEd( MODE_OLDFILE ) ) {
  710.         while( FGets( kp, buff, 82 ) && buff[0]!=26 )
  711.                FPuts( fp, buff     ) ;
  712.  
  713.         Close( kp );
  714.  
  715.         DeleteEd();
  716.     }
  717.  
  718.     if( eof ) FPuts( fp, "\032\n" );
  719. }
  720.